<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>修改主推任务</title>
        <link rel="stylesheet" href="css/reset.css" />
        <link rel="stylesheet" href="css/platform.css" />
        <link rel="stylesheet" href="css/table.css" />
        <link rel="stylesheet" href="js/ui/jquery-ui.min.css" />
        <link rel="stylesheet" href="css/mainpush.css" />
        <style>
        	.rate_btn{color:#2284e5;font-size:12px;margin-left:10px;}
        	#rateInput{min-width: 25px;max-width:80px;    border-bottom: 1px solid #000;    padding-left: 3px;}
        </style>
    </head>

    <body>
        <div class="container" ms-controller="mainController">
        	<div class="header">
                <div class="u-title">修改主推任务</div>
            </div>
            <div class="cnt-box">
                <div class="u-multiform">
                    <div class="column">
                        <div class="cell">
                            <label>任务主题：</label>
                            <span class="read-txt">{{taskTopic}}</span> 
                            <span id="hqTaskIdCell" style="display: none;">{{hqTaskId}}</span>
                        <div class="cell tasktime">
                            <label>任务时间：</label>
                            <div class="cnt-box">
                                <span class="read-txt">{{month}}</span>
                            </div>
                        </div>
                       <div class="cell">
                           <label>主推品类：</label>
                           <div class="cnt-box">
                               <span class="read-txt">{{cateName}}</span>
                           </div>
                       </div>
                       <div class="cell">
                           <label style="margin-left:-20px;">目标占比：</label>
                           <div class="cnt-box">
                               <span class="read-txt" id="rateCell">{{rate}}</span><span class="read-txt">%</span>
                  				<span class="rate_btn">修改</span>
                           </div>
                           
                       </div>
                    </div>
                </div>
            </div>
            <div class="u-tabs">
                <div class="cnt-box" style="margin-bottom: 15px;">
                    <div class="cnt push-goods">
                         <button class="u-btn small import-task" ms-click="importXls">导入新款数</button>
                         <a href="xls/addModelTemplate.xlsx"" class="temp-download">模板下载</a>
                    </div>
                </div>
                <div class="cnt-box">
                    <div class="cnt push-goods">
                        <div id="taskTable22" ms-controller="taskTable22"></div>
                        <script type="avalon" id="tabletask22">
                            <div class="tableWrapper">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th>主推类型</th>
                                            <th>款数名称</th>
                                            <th>商品编码</th>
                                            <th>目标台数</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ms-repeat-row="sources" ms-class="dis:row.commStatus==0">
                                            <td>{{row.taskType}}</td>
                                            <td>{{row.modelName}}</td>
                                            <td><div style="width:600px;height:30px;">{{row.cmmdtyCodes}}</div></td>
                                            <td>{{row.allocateNum}}</td>
                                            <td class="operate">
                                                <a ms-if="row.taskType!='B2'" href="javascript:;" ms-click="customFuncs.distributionInfo(row.modelId)">分配详情</a>
												<a href="javascript:;" ms-click="customFuncs.delPop(row)">删除</a>
                                            </td>
                                        </tr>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td colspan="8">
                                                <div class="pager">
                                                    <div class="first-page" ms-click="firstpage" ms-class={{firstpagestyle}}>首页</div>
                                                    <div class="pre-page" ms-click="prepage" ms-class={{prepagestyle}}>上一页</div>
                                                    <div class="current-page">
                                                        第<input class="current-page-num" type="text" ms-duplex="currentpage" ms-input="jumppage" />页
                                                        <span class="totalpage">共 {{totalpage}} 页</span>
                                                    </div>
                                                    <div class="next-page" ms-click="nextpage" ms-class={{nextpagestyle}}>下一页</div>
                                                    <div class="last-page" ms-click="lastpage" ms-class={{lastpagestyle}}>尾页</div>
                                                    <div class="messageinfo">{{startrow}}-{{endrow}} 共{{total}}条</div>
                                                </div>
                                            </td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </script>
                    </div>
                </div>
            </div>
        </div>
        <div ms-controller="popController">
            <div class="u-popup" id="popup_import">
                <div class="bg"></div>
                <div class="asTable">
                    <div class="asTableCell">
                        <div class="asCell alert import">
                            <a href="javascript:;" class="close btn-close">×</a>
                            <p class="title">选择导入文件</p>
                            <div class="container">
                                <form id="form_file" enctype="multipart/form-data" autocomplete="off" method="post">
                                    <input type="file" name="file" accept=".xls,.xlsx" id="upladFile" />
                                    <input type="hidden" name="hqTaskId" ms-attr-value="hqTaskId" />
                                </form>
                            </div>
                            <div class="btn-box">
                                <button class="u-btn" ms-click="uploadFile">确定</button>
                                <button class="u-btn btn-close gray">取消</button>
                            </div>
                            <div id="load-import" class="loadData">
                                <div class="la-ball-spin-clockwise-fade">
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="u-popup distribution" id="popup_distribution">
                <div class="bg"></div>
                <div class="asTable-box">
                    <div class="asTable">
                        <div class="asTableCell">
                            <div class="asCell dialog">
                                <a href="javascript:;" class="close btn-close">×</a>
                                <p class="title">分配详情</p>
                                <div class="container">
                                    <div class="search-code">
                                        <input class="u-ipt" placeholder="输入大区编码" maxlength="5" ms-duplex="searchcode" onkeyup="fastSearch(event)" ms-blur="fastSearch" />
                                        <button class="u-btn" ms-click="fastSearch">快速定位</button>
                                        <div class="err-box">
                                            <p class="u-error">请输入5位大区编码</p>
                                        </div>
                                    </div>
                                    <form id="modelAlloForm" autocomplete="off" method="post">
                                    <input type="hidden" name="modelId" class="modelIdIpt"/>
                                    <input type="hidden" name="hqTaskId" class="hqTaskIdIpt"/>
                                    <p class="total">总目标台数：<span>{{targetNum}}</span></p>
	                                    <table class="table">
	                                        <thead>
	                                            <tr>
	                                                <th>大区编码</th>
	                                                <th>大区名称</th>
	                                                <th>目标台数</th>
	                                            </tr>
	                                        </thead>
	                                        <tbody>
	                                            <tr ms-repeat-row="assignList">
	                                                <td class="region-code" ms-attr-id="td_{{row.disCode}}"><span>{{row.disCode}}</span></td>
	                                                <td>{{row.disName}}</td>
	                                                <td class="edit-ipt">
	                                                	<span style="display: none;">{{$index}}</span>
	                                                    <input class="u-ipt targetNumIpt" maxlength="7" ms-attr-value="row.targetNum" ms-blur="checkNum" />
	                                                	<input class="u-ipt areaTaskIdIpt" ms-attr-value="row.areaTaskId" type="hidden"/>
	                                                </td>
	                                            </tr>
	
	                                        </tbody>
	                                    </table>
                                    </form>
                                    <div id="load-assign" style="display: none;">
                                        <div class="la-ball-spin-clockwise-fade">
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="btn-box">
	                                <button class="u-btn" ms-click="allocateModel">保存</button>
	                                <button class="u-btn gray btn-close">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="u-popup" id="popup_tips">
                <div class="bg"></div>
                <div class="asTable">
                    <div class="asTableCell">
                        <div class="asCell alert">
                            <a href="javascript:;" class="close btn-close">×</a>
                            <p class="title">提示</p>
                            <div class="container">
                                <div class="error"></div>
                                <p style="max-height: inherit;"></p>
                            </div>
                            <div class="btn-box">
                                <button class="u-btn btn-close">确定</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="u-popup" id="popup_del">
                <div class="bg"></div>
                <div class="asTable">
                    <div class="asTableCell">
                        <div class="asCell alert">
                            <a href="javascript:;" class="close btn-close">×</a>
                            <p class="title">提示</p>
                            <div class="container">
                                <div class="warning"></div>
                                <p>确定要删除该款数吗？</p>
                            </div>
                            <div class="btn-box">
                                <button class="u-btn" ms-click="delData()">确定</button>
                                <button class="u-btn gray btn-close">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="loadData"></div>
        <script src="js/jquery.min.js"></script>
        <script src="js/avalon.shim.sn.js"></script>
        <script src="js/ui/jquery-ui.min.js"></script>
        <script src="js/ui/jquery-ui-timepicker-addon.js"></script>
        <script src="js/jquery.form.js"></script>
        <script src="js/swift-ui-table-1.1.js"></script>
        <script src="js/platform.js"></script>
        <script src="js/DataInterface/DataInterface.js"></script>
        <script src="js/editHqTask.js"></script>
        
        <script type="text/javascript">
        	$(function(){
        		$(".rate_btn").unbind('click').bind('click',function(){
	        		if($('#rateInput').length>0){
	        			return;
	        		}
        			var value = $("#rateCell").html();
        			$("#rateCell").html("");
        			$("<input id='rateInput' type='text' oldVal='"+value+"' value='"+value+"'/>").clone().appendTo($("#rateCell"));
        			$("#rateInput").focus();
        			$("#rateInput").blur(modify);
        		});
        	});
        	function jsMul(arg1,arg2){   
				var m=0,s1=arg1.toString(),s2=arg2.toString();   
				try{m+=s1.split(".")[1].length}catch(e){}   
				try{m+=s2.split(".")[1].length}catch(e){}   
				return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
			}   
        	function jsDiv(arg1,arg2){   
				 var t1=0,t2=0,r1,r2;   
				 try{t1=arg1.toString().split(".")[1].length}catch(e){}   
				 try{t2=arg2.toString().split(".")[1].length}catch(e){}   
				 with(Math){   
					 r1=Number(arg1.toString().replace(".",""))   
					 r2=Number(arg2.toString().replace(".",""))  
					 return jsMul((r1/r2),pow(10,t2-t1));   
				 }   
			 }
        	
        		var modify = function(){
           			var value = $.trim($("#rateInput").val());
           			var oldVal = $("#rateInput").attr('oldVal');
           			if(value == oldVal){
           				$("#rateCell").html(oldVal);
           				return;
           			}
           			var reg = /^[0-9]+.?[0-9]*$/;
           			if(!reg.test(value)){
           				PLATFORM.showTips("error", "占比必须为数字");
           				return;
           			}
           			
           			var tmp = jsDiv(value,100);
           			
           			if((''+tmp).length>5 ||  tmp<0.000 || tmp >1.000){
           				PLATFORM.showTips("error", "占比范围不正确");
           				return;
           			};
           			$("#rateCell").html(value).end().remove("#rateInput");
        			$.ajax({
       			        url: DI.modifyTaskRate + '?hqTaskId=' + $("#hqTaskIdCell").html() + '&rate=' + value,
       			        type: 'POST',
       			        dataType:'json',
       			        processData: false,
       			        contentType: false
       			    }).done(function (data) {
       			    	if(data.retFlag == 1){
       			    		PLATFORM.showTips("success","修改占比成功");
       			    	}else{
       			    		PLATFORM.showTips("error", data.errorMessage)
       			    	}
       			    })
            		
        		}
        	
        </script>
	</body>
</html>
